package com.car.image;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.Serializable;

import com.car.comm.Util;

import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;

public class SerializeBitmap implements Serializable{
	private static final long serialVersionUID = 1L;
	private Bitmap bmpInstance;

	public Bitmap getBmpInstance() {
		return bmpInstance;
	}

	public void setBmpInstance(Bitmap bmpInstance) {
		this.bmpInstance = bmpInstance;
	}
	
	private void writeObject(java.io.ObjectOutputStream out) throws IOException
	{
		if(bmpInstance == null){
			return ;
		}
		ByteArrayOutputStream baops = new ByteArrayOutputStream();
		bmpInstance.compress(CompressFormat.PNG, 0, baops);
		out.write(baops.toByteArray());
		out.flush();
	}
	
	private void readObject(java.io.ObjectInputStream in) 
			throws IOException, ClassNotFoundException 
	{
		byte[] bitmapData = Util.toByteArray(in);
		this.bmpInstance = BitmapFactory.decodeByteArray(bitmapData, 0, bitmapData.length);
	}
}
